import Vue from 'vue'
import VueRouter from 'vue-router'

// 懒加载
// const Home = () => {
//   import ('../components/Home.vue')
// }
// const About = () => {
//   import ('../components/About.vue')
// }
import Home from '../components/Home.vue'
import About from '../components/About.vue'

Vue.use(VueRouter) //使用插件

// 配置映射关系
const routes = [
  { path: '/', redirect: '/home' },
  {
    path: '/home',
    component: Home,
    meta: {
      title: '首页'
    }
  },
  {
    path: '/about',
    component: About,
    meta: {
      title: '关于'
    }
  }
]

const router = new VueRouter({
  routes,
  mode: 'history'
})

router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title
  next()
})

export default router